#include "GameState.h"

OptionScreen::OptionScreen():IGameState()
{
	m_stateType = EScreenType::SETTING_SCREEN;
	backgroud = new CSprite(CTexture::create("Resource\\Image\\BackGround\\OptionBG.png"));
	music = new CSprite(CTexture::create("Resource\\Image\\Button\\OnOff.png"),2,1,2,0,0);
	sound = new CSprite(CTexture::create("Resource\\Image\\Button\\OnOff.png"),2,1,2,0,0);
	if(SoundManager::isBGM_On==false)
		music->SetIndex(1);
	if(SoundManager::isSoundEffect_On==false)
		sound->SetIndex(1);
	lstButton.push_back(music);
	lstButton.push_back(sound);

	currentChoise = 0;
}

OptionScreen::~OptionScreen()
{
	Release();
}

void OptionScreen::Create()
{
	
}

void OptionScreen::Release()
{
	//if(backgroud!=NULL)
	//delete backgroud;
	//backgroud = NULL;
}

void OptionScreen::HandleInput(CInput* input,float dt)
{
	if(input->IsKeyPress(DIK_RETURN))
	{
		if(currentChoise == 0)
		{
			if(music->m_Index==0)
			{
				music->SetIndex(1);
				SoundManager::isBGM_On = false;
				SoundManager::GetInst()->StopAllBGSound();
			}
			else
			{
				music->SetIndex(0);
				SoundManager::isBGM_On = true;
				SoundManager::GetInst()->ResumeBGM();
			}
		}
		else if(currentChoise == 1)
		{
			if(sound->m_Index==0)
			{
				sound->SetIndex(1);
				SoundManager::isSoundEffect_On = false;
			}
			else
			{
				sound->SetIndex(0);
				SoundManager::isSoundEffect_On = true;
			}
		}
	}

	if(input->IsKeyPress(DIK_LEFT))
	{
		if(currentChoise<lstButton.size()-1)
			currentChoise++;
		else
			currentChoise = 0;
		SoundManager::GetInst()->PlaySoundEffect(ES_Click);
	}
	if(input->IsKeyPress(DIK_RIGHT))
	{
		if(currentChoise>0)
			currentChoise--;
		else
			currentChoise = lstButton.size()-1;
		SoundManager::GetInst()->PlaySoundEffect(ES_Click);
	}

	if(input->IsKeyPress(DIK_F))
	{
		if(GL_graphic->GetIsFullScreen()==false)
		{
			GL_graphic->ChangeViewMode(true);
			ResourceManager::GetIns()->Init();
			ExitSceen();
			StateManager::GetInstance()->ClearAllScreen();
			StateManager::GetInstance()->AddScreen(new MenuScreen());
		}
	}

	
	if(input->IsKeyPress(DIK_BACKSPACE))
	{
		ExitSceen();
	}
}

void OptionScreen::Update(float dt)
{
	for (int i = 0; i<lstButton.size();i++)
	{
		if(i==currentChoise)
		{
			if(lstButton[i]->m_fScale < 1.3f)
				lstButton[i]->m_fScale+=0.1f;
		}
		else
		{
			lstButton[i]->m_fScale = 1.0f;
		}
		lstButton[i]->Update(dt);
	}

}

void OptionScreen::Draw()
{
	D3DXMATRIX matrix;
	D3DXMatrixIdentity(&matrix);
	GL_graphic->m_pSpriteHandler->SetTransform(&matrix);
	backgroud->Draw(D3DXVECTOR2(400,300),SpriteEffect::Vertical,0,1);
	music->Draw(D3DXVECTOR2(230,380),SpriteEffect::Vertical,0,1);
	sound->Draw(D3DXVECTOR2(600,380),SpriteEffect::Vertical,0,1);
}
